
const files = require.context('@/api/modules/', true, /\.js$/);
const $API = {};

files.keys().forEach(key => {
    if (key.split('/').length !== 3) {
        Promise.reject('file error' + key + ' view service folders Refer to test folder ');
        return;
    }
    const item = files(key).default;

    let keySplit = key
        .split('/')
        .filter(item => {
            return item.indexOf('.js') !== -1;
        })[0]
        .replace('.js', '');

    let ObjectName = key.split('/')[1];
    if ($API[ObjectName]) {
        $API[ObjectName][keySplit] = new item();
    } else {
        $API[ObjectName] = {};
        $API[ObjectName][keySplit] = new item();
    }
});

export default $API;
